package com.wdb007.venus.web.api.handler;

import java.util.ArrayList;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.wdb007.venus.svc.facade.constant.Action;

@Component
public class BookcaseHandler {
    private Logger logger = LoggerFactory.getLogger(this.getClass().getName());
    @Autowired
    AmqpHandler amqpHandler;

    private boolean processBookcaseCheckRes(Action action) {
        return true;
    }

    private  boolean processBookgridCloseledRes(Action action) {
        logger.debug("processBookgridCloseledRes: {}", action.bookGridId());
        return true;
    }

    private  boolean processBookgridOpenledRes(Action action) {
        logger.debug("processBookgridOpenledRes: {}", action.bookGridId());
        return true;
    }

    private  boolean processBookgridStatusRes(Action action) {
        logger.debug("processBookgridStatusRes: {}", action.bookGridId());
        return true;
    }

    private  boolean processBookgridCheckRes(Action action) {
        ArrayList data = action.data();
        Long ts = action.ts();

        for (int i = 0; i < data.size(); i++) {
            String v = data.get(i).toString();
        }

        logger.debug(ts.toString());
        return true;
    }

    private  boolean processBookgridUnlockRes(Action action) {
        logger.debug("processBookgridUnlockRes: {}", action.bookGridId());
        return true;
    }

    public boolean process(Map<String, Object> msg) {
        logger.debug(msg.toString());

        Action action = new Action(msg);
        if (action.is(Action.bookcase_check_res)) {
            return processBookcaseCheckRes(action);
        }
        else if (action.is(Action.bookgrid_closeled_res)) {
            return processBookgridCloseledRes(action);
        }
        else if (action.is(Action.bookgrid_openled_res)) {
            return processBookgridOpenledRes(action);
        }
        else if (action.is(Action.bookgrid_status_res)) {
            return processBookgridStatusRes(action);
        }
        else if (action.is(Action.bookcase_check_res)) {
            return processBookgridCheckRes(action);
        }
        else if (action.is(Action.bookgrid_unlock_res)) {
            return processBookgridUnlockRes(action);
        }

        return false;
    }
}